package cn.wolfcode.trip.app.controller;

import cn.wolfcode.trip.base.domain.AtRecord;
import cn.wolfcode.trip.base.query.AtQueryObject;
import cn.wolfcode.trip.base.query.QueryObject;
import cn.wolfcode.trip.base.service.IAtSomeOneService;
import cn.wolfcode.trip.base.util.JSONResult;
import com.github.pagehelper.PageInfo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * At @ someOne功能controller
 *
 * @author Wangyk
 * @date 2019/1/17 18:40
 */
@Api(value = "@功能", description = "@记录控制器")
@RestController
@RequestMapping("atSomeOne")
public class AtSomeOneController {
    @Autowired
    private IAtSomeOneService atSomeOneService;

    /**
     * 添加一条@记录
     *
     * @param atRecord @记录的信息
     * @return 添加结果
     */
    @PostMapping()
    @ApiOperation(value = "@记录", notes = "添加@记录")
    @ApiImplicitParams({
            @ApiImplicitParam(value = "发送者Id", name = "senderUser.id", dataType = "Long", required = true),
            @ApiImplicitParam(value = "接收者Id", name = "receiveUser.id", dataType = "Long", required = true),
            @ApiImplicitParam(value = "记录所在的位置(游记/攻略/评论)", name = "targetType", dataType = "int", required = true),
            @ApiImplicitParam(value = "记录所在的位置(游记/攻略/评论)", name = "targetId", dataType = "Long", required = true),
            @ApiImplicitParam(value = "@展示信息", name = "message", dataType = "String", required = true),
    })
    public JSONResult addAAtRecord(AtRecord atRecord) {
        JSONResult jsonResult = new JSONResult();
        try {
            //添加
            atSomeOneService.addAAtRecord(atRecord);

        } catch (Exception e) {
            jsonResult.mark(e.getMessage());
        }
        return jsonResult;
    }

    /**
     * 查询at记录
     *
     * @param qo 查询条件
     * @return at记录集合
     */
    @GetMapping("{receiveUserId}")
    @ApiImplicitParams({
            @ApiImplicitParam(value = "接收者Id", name = "receiveUserId", dataType = "Long", required = true),
            @ApiImplicitParam(value = "发送者Id", name = "senderUserId", dataType = "Long"),
            @ApiImplicitParam(value = "被at的类型", name = "targetType", dataType = "int"),
            @ApiImplicitParam(value = "被at的类型的id", name = "targetId", dataType = "Long"),
    })
    public Object getAtReceivedByAUser(AtQueryObject qo) {
        //1:查询
        PageInfo atRecordPageInfo = atSomeOneService.getAtRecordsByQueryObject(qo);
        return atRecordPageInfo;
    }

    /**
     * 查询at记录
     *
     * @param qo 查询条件
     * @return at记录集合
     */
    @GetMapping()
    @ApiImplicitParams({
            @ApiImplicitParam(value = "接收者Id", name = "receiveUserId", dataType = "Long"),
            @ApiImplicitParam(value = "发送者Id", name = "senderUserId", dataType = "Long"),
            @ApiImplicitParam(value = "被at的类型", name = "targetType", dataType = "int"),
            @ApiImplicitParam(value = "被at的类型的id", name = "targetId", dataType = "Long"),
    })
    public Object getAtRecordsByAUser(AtQueryObject qo) {
        //1:查询
        PageInfo atRecordPageInfo = atSomeOneService.getAtRecordsByQueryObject(qo);
        return atRecordPageInfo;
    }


}
